package com.glory.brepda.utils;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.util.Base64;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Toast;

import com.github.chrisbanes.photoview.PhotoView;
import com.glory.brepda.R;

import java.io.File;

public class ShowDialog {

    public static void showDialog(Context context, String message,String title){
        AlertDialog dialog=null;
        dialog = new AlertDialog.Builder(context).setTitle(title)
                .setMessage(message)
                .setIcon(R.drawable.lanjian)
                .setPositiveButton("确定",null)
                .setNegativeButton("取消",null)
                .create();
        dialog.show();
    }

    public static void showImagePreviewDialog(Context context, String base64Str) {
        Dialog dialog = new Dialog(context, android.R.style.Theme_Black_NoTitleBar_Fullscreen);
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_preview_image, null);
        PhotoView photoView = view.findViewById(R.id.photoView);

        try {
            byte[] decodedBytes = Base64.decode(base64Str, Base64.DEFAULT);
            Bitmap bitmap = BitmapFactory.decodeByteArray(decodedBytes, 0, decodedBytes.length);
            photoView.setImageBitmap(bitmap);
        } catch (Exception e) {
            Toast.makeText(context, "图片加载失败", Toast.LENGTH_SHORT).show();
            dialog.dismiss();
            return;
        }

        photoView.setOnClickListener(v -> dialog.dismiss()); // 点击图片关闭预览
        dialog.setContentView(view);
        dialog.show();
    }


}
